<template>
	<view>
		<Header title="修改信息"></Header>
		<view class="toubu">
			<view class="content_content_con shadow">
				<view class="shangjia line">
					<view>员工账号</view>
					<view class="last_choose">{{zhanghao}}</view>
				</view>
			</view>
			<view class="content_content_con shadow">
				<view class="shangjia" v-for="(item,index) in list" :key="index">
					<view class="heise_ziti">{{item.title}}</view>
					<view v-if="item.img" class="qianhuione_ziti" @click="tanchu(index,item.add_kezi_xiabiao,item.tankuang_xiabiao)">
						<text class="two_eight" v-if="item.val!==''">
							{{item.val}}
						</text>
						<text class="two_eight num_zhanghao" v-else>
							{{item.placeholder}}
						</text>
						<image :src="item.img">
					</view>
					<view  v-else >
						<!-- <input v-if="item.type=='text'" type="text" :placeholder="item.placeholder" v-model="item.val" class="shangjia_input"
							placeholder-class="shangjia_input_placeholder"  :maxlength="item.maxlength" >
						<input v-else type="password" :placeholder="item.placeholder" v-model="item.val" class="shangjia_input"
							placeholder-class="shangjia_input_placeholder"  :maxlength="item.maxlength" > -->
							<input v-if="item.type=='text'" type="text" :placeholder="item.placeholder" v-model="item.val" class="shangjia_input"
								placeholder-class="shangjia_input_placeholder"  :maxlength="item.maxlength" >
								<input v-else-if="item.type=='number'" type="number" :placeholder="item.placeholder" v-model="item.val" class="shangjia_input"
									placeholder-class="shangjia_input_placeholder"  :maxlength="item.maxlength" >
							<input v-else type="password" :placeholder="item.placeholder" v-model="item.val" class="shangjia_input"
								placeholder-class="shangjia_input_placeholder"  :maxlength="item.maxlength" >
					</view>
						<!--  -->
						<!--  -->
				</view>
			</view>
			<view class="content_content_con shadow">
				<view class="shangjia line">
					<view>账号状态</view>
					<view class="uni-padding-wrap uni-common-mt">
						<switch :checked="status" color="#FF609A" style="transform:scale(0.7)" @change="switch1Change" />
						<!-- <switch  style="transform:scale(0.7)"/> -->
					</view>
				</view>
			</view>
			
		</view>
		<view class="yinhangka_guanli__footer">
			<view class="anniu" @click="queding">确认修改员工</view>
		</view>
		<requestLoading></requestLoading>
	</view>
</template>

<script>
	 export default {
		data() {
			return {
				tishi: 1 ,//展示加载动画
				list: [{
						title: '姓名',
						val: '',
						placeholder:'请输入员工姓名',
						type:'text',
						maxlength:'30'
					},{
						title: '联系方式',
						val: '',
						placeholder:'请输入员工联系方式',
						maxlength:'11',
						type:'number',
					},{
						title: '密码',
						val: '',
						placeholder:'请输入密码',
					}
				],
				zhanghao:'',
				dizhi_xiabiao:0,
				show: false,   //昵称弹框
				beizhu:'',      //备注
				tupian_list:[],
				status:'' ,// 0 可用  1 不可用
				
				// userid:''
				
			} 
		},
		
		onLoad(option) {
			this.userid=option.userid;
			console.log(this.userid,"this.userid")
		},
		onShow(){
			this.xinxi()
		},
		methods:{
			xinxi(){
				var that = this;
				this.configure.ajax({
					url: 'wode/userself',
					tishi: that.tishi,
					data: {
						userid:that.userid,
					},
					method: 'POST',
					success: function(res) {
						console.log(res,"res")
						console.log("成功")
						that.zhanghao=res.data.user_name
						that.list[0].val=res.data.nick_name
						that.list[1].val=res.data.phonenumber
						// that.list[3].val=res.data.s_address
						that.status=res.data.type.toString()
						}
					
				})
			},
			
			queding(){
				var that = this;
				for (var i = 0; i < that.list.length; i++) {
					// if (that.list[i].val == '') {
					// 	uni.showToast({
					// 		title: that.list[i].placeholder,
					// 		icon: "none"
					// 	});
					// 	return false;
					// }
					if (that.publics.patt1.test(that.list[i].val)) {
						uni.showToast({
							title: that.list[i].placeholder,
							icon: "none"
						});
						return false;
					}
				}
				
				if (that.list[0].val == '') {
					uni.showToast({
						title: '请输入员工姓名',
						icon: "none"
					});
					return false;
				}
				if (that.list[1].val == '') {
					uni.showToast({
						title: '请输入员工联系方式',
						icon: "none"
					});
					return false;
				}
				if(!/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(that.list[1].val)){
					uni.showToast({
						title: '手机号格式错误',
						icon: "none"
					});
					return false;
				}
				
				
				if (that.list[1].val.length != 11) {
					uni.showToast({
						title: '手机号长度错误',
						icon: "none"
					});
					return false;
				}
				if(that.list[2].val===''){
					// debugger
					that.list[2].val=''
				}else if(!that.publics.password.test(that.list[2].val)){
						uni.showToast({
							title:"密码格式错误,拼音+数字,不能低于六位",
							icon:"none"
						})
						return false;
					};
				
				
				this.configure.ajax({
					url: 'wode/shopchangeUser',
					tishi: that.tishi,
					data: {
						nick_name:that.list[0].val,
						phonenumber:that.list[1].val,
						password:that.list[2].val,
						status:that.status,
						username:that.zhanghao,
						userid:that.userid,
					},
					method: 'POST',
					success: function(res) {
							uni.showToast({
								title: '修改成功',
								icon: "none"
							});
							setTimeout(() => {
								uni.navigateBack();
							}, 500);
						
					}
				})
			},
			switch1Change: function (e) {
				var that=this;
				that.status=e.detail.value ? 0 : 1;
				console.log(that.status,"e.detail.value")
			},
		}
	}
</script>

<style lang="scss" scoped>
	.shangjia view:last-child {
		font-size: 30rpx;
		image {
			width: 40rpx;
			height: 40rpx;
			vertical-align: middle;
			padding-left: 10rpx;
		}
	}
	.line{
		border-bottom:none;
	}
	.last_choose {
		font-size: 28rpx !important;
		color:$qianhuione_ziti;
		image {
			width: 40rpx;
			height: 40rpx;
			padding-left: 10rpx;
			vertical-align: middle;
		}
	}
	.shangjia_title {
		margin-top: 40rpx;
		margin-bottom: 30rpx;
		font-size: 30rpx;
		span {
			color: $qianhui_ziti;
			font-size: 20rpx;
			font-weight: 500;
		}
	}
	.add_input {
		font-size: 24rpx;
		color: $qianhui_ziti;
		text-align: left;
		margin-top: 48rpx;
	}
	.yinhangka_guanli__footer {
		width: 100%;
		height: 140rpx;
		position: fixed;
		bottom: 280rpx;
		background: $white_ziti;
		view {
			margin-top: 30rpx;
		}
	}
	.shangchaun_photo_con{
		display: flex;
	}
	.num_zhanghao{
		color:$qianhui_ziti;
	}
</style>
